<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改用户')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-webUser-edit" th:object="${webUser}">
            <h4 class="form-header h4">基本信息</h4>
            <input name="id" th:field="*{id}" type="hidden">
            <input name="deptId"  type="hidden"  th:field="*{deptId}" id="treeId"/>
            <input name="recycleTypeId" type="hidden" th:field="*{recycleTypeId}"/>
            <div class="form-group hidden">
                <label class="col-sm-3 control-label is-required">用户名：</label>
                <div class="col-sm-8">
                    <input name="username" th:field="*{username}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">昵称：</label>
                <div class="col-sm-8">
                    <input name="nickname" th:field="*{nickname}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">真实姓名：</label>
                <div class="col-sm-8">
                    <input name="realname" th:field="*{realname}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">归属门店：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input class="form-control" type="text" name="deptName" onclick="selectDeptTree()" id="treeName" th:field="*{deptName}">
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">预约项目：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input name="recycleType" th:attr="data-id=*{recycleTypeId}" th:field="*{recycleType}" class="form-control" type="text">
                        <div class="input-group-btn">
                            <button type="button" class="btn btn-white dropdown-toggle" data-toggle="dropdown">
                                <span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu dropdown-menu-right" role="menu">
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">手机号：</label>
                <div class="col-sm-8">
                    <input name="mobile" th:field="*{mobile}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">状态：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('sys_normal_disable')}">
                        <input type="radio" th:id="${'status_' + dict.dictCode}" name="status" th:value="${dict.dictValue}" th:field="*{status}" required>
                        <label th:for="${'status_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">会员类型：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('web_user_type')}">
                        <input type="radio" th:id="${'status_' + dict.dictCode}" name="userType" th:value="${dict.dictValue}" th:field="*{userType}" required>
                        <label th:for="${'status_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">性别：</label>
                <div class="col-sm-8">
                    <div class="radio-box">
                        <input type="radio" th:id="男" name="sex" th:value="男" th:field="*{sex}" required>
                        <label th:for="男" th:text="男"></label>
                    </div>
                    <div class="radio-box">
                        <input type="radio" th:id="女" name="sex" th:value="女" th:field="*{sex}" required>
                        <label th:for="女" th:text="女"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">头像：</label>
                <div class="col-sm-8">
                    <input type="hidden" name="headPic" th:field="*{headPic}">
                    <div class="file-loading">
                        <input class="form-control file-upload" id="headPic" name="file" type="file">
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">认证状态：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('auth_status')}">
                        <input type="radio" th:id="${'realAuth_' + dict.dictCode}" name="realAuth" th:value="${dict.dictValue}" th:field="*{realAuth}" required>
                        <label th:for="${'realAuth_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>


            <h4 class="form-header h4">身份信息</h4>
            <div class="form-group">
                <label class="col-sm-3 control-label">身份证号码：</label>
                <div class="col-sm-8">
                    <input name="idcard" th:value="${account.idcard}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">身份证正面照：</label>
                <div class="col-sm-8">
                    <input type="hidden" name="idCardA" th:field="${account.idCardA}">
                    <div class="file-loading">
                        <input class="form-control file-upload" id="idCardA" name="file" type="file">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">身份证反面照：</label>
                <div class="col-sm-8">
                    <input type="hidden" name="idCardB" th:field="${account.idCardB}">
                    <div class="file-loading">
                        <input class="form-control file-upload" id="idCardB" name="file" type="file">
                    </div>
                </div>
            </div>
            <h4 class="form-header h4">银行卡信息</h4>
            <div class="form-group">
                <label class="col-sm-3 control-label">绑定类型</label>
                <div class="col-sm-8">
                    <select name="bindType" class="form-control m-b">
                        <option value=""  th:field="${account.bindType}">--</option>
                        <option value="1"  th:field="${account.bindType}">银行卡</option>
                        <option value="2"  th:field="${account.bindType}">支付宝</option>
                    </select>
                    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 对应到财务打款</span>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">开户银行：</label>
                <div class="col-sm-8">
                    <input name="bankType" th:field="${account.bankType}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">开户行账号：</label>
                <div class="col-sm-8">
                    <input name="bankNo" th:field="${account.bankNo}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">支付宝账号：</label>
                <div class="col-sm-8">
                    <input name="alipayNo" th:field="${account.alipayNo}" class="form-control" type="text">
                </div>
            </div>
        </form>
    </div>
    <div class="row">
        <div class="col-sm-offset-5 col-sm-10">
            <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
            <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <th:block th:include="include :: bootstrap-suggest-js" />
    <script th:inline="javascript">
        var prefix = ctx + "system/webUser";
        $("#form-webUser-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                var recycleTypeId = $("#recycleType").attr("data-id");
                $("#recycleTypeId").val(recycleTypeId);
                $.operate.save(prefix + "/edit", $('#form-webUser-edit').serialize());
            }
        }

        $("input[name='lastLoginDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
         $(".file-upload").each(function (i) {
            var val = $("input[name='" + this.id + "']").val()
            $(this).fileinput({
                'uploadUrl': ctx + 'common/upload',
                initialPreviewAsData: true,
                initialPreview: [val],
                maxFileCount: 1,
                autoReplace: true
            }).on('fileuploaded', function (event, data, previewId, index) {
                $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
            }).on('fileremoved', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
            })
            $(this).fileinput('_initFileActions');
        });



        /* 用户管理-修改-选择部门树 */
        function selectDeptTree() {
        	var deptId = $.common.isEmpty($("#treeId").val()) ? "100" : $("#treeId").val();
            var url = ctx + "system/dept/selectDeptTree/" + deptId;
		    var options = {
				title: '选择部门',
				width: "380",
				url: url,
				callBack: doSubmit
			};
			$.modal.openOptions(options);
		}

		function doSubmit(index, layero){
			var tree = layero.find("iframe")[0].contentWindow.$._tree;
   			var body = layer.getChildFrame('body', index);
   			$("#treeId").val(body.find('#treeId').val());
   			$("#treeName").val(body.find('#treeName').val());
   			layer.close(index);
		}

		var listRecycleType = [[${listRecycleType}]];
        if(typeof listRecycleType =="string"){
            listRecycleType = eval(listRecycleType);
        }

        var values=[];
        for(var index in listRecycleType){
            var val = {};
            val.id = listRecycleType[index].id;
            val.name = listRecycleType[index].name;
            values.push(val);
        }
        //data 数据中获取
        $("#recycleType").bsSuggest("init",{
            idField: "id",
            keyField: "name",
            clearable: true,
            effectiveFields:["name"],
            effectiveFieldsAlias:{name: "姓名"},
            data: {
                'value': values
            }
        })

    </script>
</body>
</html>